<?php
include_once('admin_global.php');
bn_include_lib('bn_jquery');
$theme->add_block('body');

$tree=new bn_menuctrl;
$tree->textCOL='cat';
$cat=new bn_category;

if(isset($_POST['cmd']))
{
    extract($_POST);
    if($cmd=='submit')
      $cat->insert($category,$descr,$row_id);  
    if($cmd=='delete')
    $cat->delete($id);
    
    if($cmd=='edit')
    $cat->update($category,$descr,$row_id);
    
    die($cat->treeview('cat_list'));
}

$theme->add_script(jquery_submit_show('#submit','submit','#cat_div','#show',array('cls'=>'$("#row_id").val("");')));
$theme->add_script(jquery_submit_show('#edit','edit','#cat_div','#show',array('cls'=>'$("#row_id").val("");')));
$theme->add_script(jquery_element('#clear','click','
$("#category").val("");
$("#descr").val($(this).attr(""));
$("#row_id").val($(this).attr(""));
$("#cat_list a").css("background-color","");
'));
$theme->add_script(jquery_element('#delete','click','
if(confirm("'.$lang[12].'"))
{
$.post(window.location.href,{cmd:"delete",id:$("#row_id").val()},function(data){$("#show").html(data);});
}
'));
$theme->add_script(jquery_element('#cat_list a','click','
$("#category").val($(this).text());
$("#descr").val($(this).attr("title"));
$("#row_id").val($(this).attr("id-data"));
'));
?>
<div id="cat_div">
<label><?php echo $lang[13] ?></label>
<br />
<input type="text" size="35" autocomplete="on" name="category" id="category" class="input-text"/>
<br />
<label><?php echo $lang[14] ?></label>
<br />
<textarea cols="50" rows="5" wrap="virtual" name="descr" id="descr" class="input-text"></textarea>
<br />
<input type="submit" name="submit" id="submit" class="button" value="<?php echo $lang[15] ?>"/>
<input type="submit" name="edit" id="edit" value="<?php echo $lang[16] ?>" class="button blue"/>
<input type="submit" name="delete" id="delete" value="<?php echo $lang[17] ?>" class="button red"/>
<input type="button" name="clear" id="clear" value="<?php echo $lang[18] ?>" class="button"/>
<input type="hidden" name="row_id" id="row_id"/>
<br /><br />
<div id="show">
<?php
$cat->treeview('cat_list');
?>
</div>
</div>
<?php
echo $cat->command_script;
$theme->render();
?>